/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import dominio.Especialidad;
import dominio.Subarea;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import negocio.EspecialidadNegocio;
import utilidades.JFondo;

/**
 *
 * @author Richard
 */
public class JIF_Subarea extends javax.swing.JInternalFrame {

    /**
     * Creates new form JIF_insertarAsignatura
     */
    private LinkedList<Subarea> subareas;
    private int accion = 0; //1=Insertar,2=Modificar y 3=Eliminar
    private EspecialidadNegocio especialidadBus = new EspecialidadNegocio();
    private Subarea subarea = new Subarea();
    private Especialidad especialidad = new Especialidad();

    public JIF_Subarea() {
        initComponents();
        JP_insertarAsignatura.setBorder(new JFondo("../imagenes/fondo_1.jpg"));
        JL_Sigla.setVisible(false);
        JTF_Sigla.setVisible(false);
        JL_Nivel.setVisible(false);
        JTF_Nivel.setVisible(false);
        JB_Aceptar.setVisible(false);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JP_insertarAsignatura = new javax.swing.JPanel();
        JL_Titulo = new javax.swing.JLabel();
        JL_Sigla = new javax.swing.JLabel();
        JTF_Sigla = new javax.swing.JTextField();
        JL_Nivel = new javax.swing.JLabel();
        JTF_Nivel = new javax.swing.JTextField();
        JB_Aceptar = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        JMI_nuevaAsignatura = new javax.swing.JMenu();
        JMI_Ingresar = new javax.swing.JMenuItem();
        JMI_editar = new javax.swing.JMenu();
        JMI_Modificar = new javax.swing.JMenuItem();
        JMI_borrar = new javax.swing.JMenu();
        JMI_Eliminar = new javax.swing.JMenuItem();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Mantenimiento Especialidad");
        setMaximumSize(new java.awt.Dimension(1000, 500));
        setMinimumSize(new java.awt.Dimension(100, 50));
        setName(""); // NOI18N
        setPreferredSize(new java.awt.Dimension(1000, 500));

        JL_Titulo.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        JL_Titulo.setText("Especialidad");

        JL_Sigla.setText("Sigla:");

        JL_Nivel.setText("Nivel:");

        JTF_Nivel.setMaximumSize(new java.awt.Dimension(25, 25));
        JTF_Nivel.setMinimumSize(new java.awt.Dimension(25, 25));

        JB_Aceptar.setText("Aceptar");
        JB_Aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_AceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JP_insertarAsignaturaLayout = new javax.swing.GroupLayout(JP_insertarAsignatura);
        JP_insertarAsignatura.setLayout(JP_insertarAsignaturaLayout);
        JP_insertarAsignaturaLayout.setHorizontalGroup(
            JP_insertarAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_insertarAsignaturaLayout.createSequentialGroup()
                .addGap(423, 423, 423)
                .addComponent(JL_Titulo)
                .addGap(206, 206, 206))
            .addGroup(JP_insertarAsignaturaLayout.createSequentialGroup()
                .addGap(359, 359, 359)
                .addGroup(JP_insertarAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JL_Nivel)
                    .addComponent(JL_Sigla))
                .addGap(36, 36, 36)
                .addGroup(JP_insertarAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JP_insertarAsignaturaLayout.createSequentialGroup()
                        .addComponent(JB_Aceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(JP_insertarAsignaturaLayout.createSequentialGroup()
                        .addGroup(JP_insertarAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JTF_Sigla, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                            .addComponent(JTF_Nivel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(281, 281, 281))))
        );
        JP_insertarAsignaturaLayout.setVerticalGroup(
            JP_insertarAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_insertarAsignaturaLayout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(JL_Titulo)
                .addGap(53, 53, 53)
                .addGroup(JP_insertarAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_Sigla)
                    .addComponent(JTF_Sigla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JP_insertarAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_Nivel)
                    .addComponent(JTF_Nivel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(64, 64, 64)
                .addComponent(JB_Aceptar)
                .addContainerGap(179, Short.MAX_VALUE))
        );

        JMI_nuevaAsignatura.setText("Ingresar");

        JMI_Ingresar.setText("Ingresar Especialidad");
        JMI_Ingresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMI_IngresarActionPerformed(evt);
            }
        });
        JMI_nuevaAsignatura.add(JMI_Ingresar);

        jMenuBar1.add(JMI_nuevaAsignatura);

        JMI_editar.setText("Modificar");

        JMI_Modificar.setText("Modificar Especialidad");
        JMI_Modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMI_ModificarActionPerformed(evt);
            }
        });
        JMI_editar.add(JMI_Modificar);

        jMenuBar1.add(JMI_editar);

        JMI_borrar.setText("Eliminar");

        JMI_Eliminar.setText("Eliminar Especialidad");
        JMI_Eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMI_EliminarActionPerformed(evt);
            }
        });
        JMI_borrar.add(JMI_Eliminar);

        jMenuBar1.add(JMI_borrar);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(JP_insertarAsignatura, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JP_insertarAsignatura, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JB_AceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_AceptarActionPerformed
        try {
            
            switch (accion) {
                case 1:
                    especialidad.setNombreEspecialidad(JTF_Nivel.getText());
                    especialidadBus.ingresarEspecialidad(especialidad);
                    break;
                case 2:
                    especialidad.setNombreEspecialidad(JTF_Nivel.getText());
                    especialidad.setSubareas(subareas);
                    especialidadBus.modificarEspecialidad(especialidad);
                    break;
                case 3:
                    especialidad.setIdEspecialidad(Integer.parseInt(JTF_Sigla.getText()));
                    especialidadBus.eliminarEspecialidad(especialidad);
                    break;
            }
        } catch (SQLException ex) {
            Logger.getLogger(JIF_Subarea.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_JB_AceptarActionPerformed

    private void JMI_IngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMI_IngresarActionPerformed
        JL_Titulo.setText("Ingresar Especialidad");
        JL_Nivel.setVisible(true);
        JTF_Nivel.setVisible(true);
        JTF_Nivel.setEnabled(true);
        JB_Aceptar.setVisible(true);
        JL_Sigla.setVisible(false);
        JTF_Sigla.setVisible(false);
        accion = 1;
    }//GEN-LAST:event_JMI_IngresarActionPerformed

    private void JMI_ModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMI_ModificarActionPerformed
        JL_Titulo.setText("Modificar Especialidad");
        JL_Nivel.setVisible(true);
        JTF_Nivel.setVisible(true);
        JTF_Nivel.setEnabled(false);
        JB_Aceptar.setVisible(true);
        JL_Sigla.setVisible(true);
        JTF_Sigla.setVisible(true);
        accion = 2;
    }//GEN-LAST:event_JMI_ModificarActionPerformed

    private void JMI_EliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMI_EliminarActionPerformed
        JL_Titulo.setText("Eliminar Especialidad");
        JL_Nivel.setVisible(true);
        JTF_Nivel.setVisible(true);
        JTF_Nivel.setEnabled(false);
        JB_Aceptar.setVisible(true);
        JL_Sigla.setVisible(true);
        JTF_Sigla.setVisible(true);
        JB_Aceptar.setEnabled(false);
        accion = 3;
    }//GEN-LAST:event_JMI_EliminarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JB_Aceptar;
    private javax.swing.JLabel JL_Nivel;
    private javax.swing.JLabel JL_Sigla;
    private javax.swing.JLabel JL_Titulo;
    private javax.swing.JMenuItem JMI_Eliminar;
    private javax.swing.JMenuItem JMI_Ingresar;
    private javax.swing.JMenuItem JMI_Modificar;
    private javax.swing.JMenu JMI_borrar;
    private javax.swing.JMenu JMI_editar;
    private javax.swing.JMenu JMI_nuevaAsignatura;
    private javax.swing.JPanel JP_insertarAsignatura;
    private javax.swing.JTextField JTF_Nivel;
    private javax.swing.JTextField JTF_Sigla;
    private javax.swing.JMenuBar jMenuBar1;
    // End of variables declaration//GEN-END:variables
}
